package com.action;

import com.hdb.TUser;

import org.apache.struts2.convention.annotation.*;

@ParentPackage("default")
@Namespace("/user")
@Results({
        @Result(name = "succeed", location = "/common/succeed.jsp"),
        @Result(name = "winClose", location = "/common/winClose.jsp"),
})
@InterceptorRef("userStack")/*设置用户过滤器*/
public class UserAction extends BasicAction {
    private String message;
    private String path;
    private int userId;
    private String userName;
    private String userPw;
    private String userNowPw;
    private String userRealName;
    private int userSex;
    private String userTel;
    private String userEmail;
    private String userQq;
    private int page;
    /*用户登出*/
    @Action("userLogout")
    public String userLogout() {
        setUser(null);
        setCart(null);
        return "index";
    }
    /*修改个人信息*/
    @Action("edit")
    public String userEdit() {
        TUser user = db.userDAO.findById(getUser().getUserId());
        if (user == null) {
            setMessage("用户不存在");
            return "winClose";
        }
        if (!userNowPw.equals(user.getUserPw())) {
            setMessage("当前密码错误,请核对后重试");
            return "winClose";
        }
        if (userPw.trim().length() >= 6) {
            user.setUserPw(userPw);
        }
        user.setUserTel(userTel);
        user.setUserEmail(userEmail);
        user.setUserQq(userQq);
        if (db.userDAO.attach(user)) {
            setMessage("修改成功");
            setUser(user);
        } else {
            setMessage("修改失败");
        }
        return "winClose";
    }

    public String getUserNowPw() {
        return userNowPw;
    }

    public void setUserNowPw(String userNowPw) {
        this.userNowPw = userNowPw;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPw() {
        return userPw;
    }

    public void setUserPw(String userPw) {
        this.userPw = userPw;
    }

    public String getUserRealName() {
        return userRealName;
    }

    public void setUserRealName(String userRealName) {
        this.userRealName = userRealName;
    }

    public int getUserSex() {
        return userSex;
    }

    public void setUserSex(int userSex) {
        this.userSex = userSex;
    }

    public String getUserTel() {
        return userTel;
    }

    public void setUserTel(String userTel) {
        this.userTel = userTel;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public String getUserQq() {
        return userQq;
    }

    public void setUserQq(String userQq) {
        this.userQq = userQq;
    }

    @Override
    public int getPage() {
        return page;
    }

    @Override
    public void setPage(int page) {
        this.page = page;
    }
}
